using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_MBF_BuyGiftCards : Member, IRequiresSessionState
{
	protected Repeater Repeater_Festival;
	protected Button btn_next;
	protected string JSInitCode = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindRP_Festival();
		}
	}
	protected void BindRP_Festival()
	{
		DataSet list = Blls.bllFestival.GetList(" dbo.[GetGiftCategoryCount](FestivalName)>0");
		this.Repeater_Festival.DataSource = list;
		if (list != null && list.Tables[0].Rows.Count > 0)
		{
			this.JSInitCode = "";
			for (int i = 0; i < list.Tables[0].Rows.Count; i++)
			{
				this.JSInitCode += string.Format("bind_click(\"giftcard_{0}\");", list.Tables[0].Rows[i]["FestivalName"]);
			}
		}
		this.Repeater_Festival.DataBind();
	}
	protected void Repeater_Festival_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
		{
			Repeater repeater = (Repeater)e.Item.FindControl("Repeater_category");
			DataRowView dataRowView = (DataRowView)e.Item.DataItem;
			string arg = dataRowView["FestivalName"].IsNull(new object[0]);
			DataTable dataSource = Blls.bllGiftCategory.GetList(string.Format("FestivalName='{0}'", arg)).Tables[0];
			repeater.DataSource = dataSource;
			repeater.DataBind();
		}
	}
	protected string GetFeceValues(object obj)
	{
		string str = obj.IsNull(new object[0]);
		DataTable dataTable = Blls.bllGiftFaceValue.GetList("FaceValue", "FestivalName='" + str + "'").Tables[0];
		string text = "";
		foreach (DataRow dataRow in dataTable.Rows)
		{
			text = text + dataRow[0] + "/";
		}
		return text.TrimEnd(new char[]
		{
			'/'
		});
	}
	protected void btn_next_Click(object sender, EventArgs e)
	{
		UserGiftCardModel userGiftCardModel = new UserGiftCardModel();
		userGiftCardModel.BuyID = new int?(base.user.UserID);
		userGiftCardModel.Balance = (userGiftCardModel.FaceValue = new decimal?(base.Request["selectFaceValue"].ToDecimal2()));
		userGiftCardModel.FestivalName = base.Request["h_FestivalName"];
		userGiftCardModel.Title = base.Request.Form["h_Title"];
		userGiftCardModel.ReceiveEmail = base.Request["txtReceiveEmail"];
		userGiftCardModel.RecieveID = new int?(base.Request["h_RecieveID"].ToInt32(new int[0]));
		userGiftCardModel.LeaveWords = base.Request["ta_LeaveWords"].Replace("_", "");
		userGiftCardModel.Picture = Path.GetFileName(base.Request["h_Picture"]);
		userGiftCardModel.Password = Text.Random(8, -1);
		userGiftCardModel.CardNumber = DateTime.Now.ToString("yyyyMMddhhmmssfff") + Text.Random(3, 2);
		userGiftCardModel.BuyTime = new DateTime?(DateTime.Now);
		userGiftCardModel.CouponAmount = userGiftCardModel.FaceValue * 0.01m * base.Request["h_disrate"].ToDecimal2();
		JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
		string str = javaScriptSerializer.Serialize(userGiftCardModel);
		str = Blls.bllGiftCard.ToString(userGiftCardModel);
		base.Response.Redirect("MBF_PayGiftCards.aspx?model=" + str, false);
	}
	private string GetUserNameByid(int? userid)
	{
		return StaticFun.GetUserNameByid(userid);
	}
}
